package com.zx.mobile.service.proxy;

import com.zx.map.service.model.MerchantInfoModel;
import com.zx.map.service.model.OrdLogModel;
import com.zx.map.utils.SUConstants;
import com.zx.mobile.MobileCommonHelper;
import com.zx.mobile.domain.interf.CardPayOrderRequest;
import com.zx.mobile.domain.interf.CardPayOrderResponse;
import com.zx.platform.utils.PmpUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

public class CardPayOrderCommonProxy {

    /**
     * 刷卡信息合法性校验
     *
     * @param cardPayOrderRequest
     * @return
     */
    public static String checkCardPay(CardPayOrderRequest cardPayOrderRequest) {
        if (StringUtils.isBlank(cardPayOrderRequest.getAppUserId())) {
            return "输入项必填";
        }
        if (StringUtils.isNotBlank(cardPayOrderRequest.getPlatformType())) {
            if (!("A".equals(cardPayOrderRequest.getPlatformType()) || "iPhone"
                    .equals(cardPayOrderRequest.getPlatformType()))) {
                return "平台类型不合法";
            }
        } else {
            return "输入项必填";
        }

        if (StringUtils.isBlank(cardPayOrderRequest.getTelephone())) {
            return "输入项必填";
        }

        if (StringUtils.isBlank(cardPayOrderRequest.getTerminalId())) {
            return "输入项必填";
        }
        if (StringUtils.isBlank(cardPayOrderRequest.getTradeAmount())) {
            return "输入项必填";
        }

        return null;
    }

    /**
     * 刷卡订单信息
     *
     * @param cardPayOrderRequest
     * @return
     */
    public static OrdLogModel getCardPayOrdLogModel(
            CardPayOrderRequest cardPayOrderRequest, MerchantInfoModel temp) {
        // 保存订单信息
        OrdLogModel ordLogModel = new OrdLogModel();
        ordLogModel.setAgentId(temp.getAgentId());
        ordLogModel.setAgentSysAccount(temp.getAgentSysAccount());
        ordLogModel.setCreateDate(new Date());
        ordLogModel.setMerchantId(temp.getMerchantId());
        ordLogModel.setMerSysAccount(temp.getSysAccount());
        ordLogModel.setTransType(SUConstants.TRANSTYPE_CARDINCOME);//刷卡收款
        ordLogModel.setTransStatus(MobileCommonHelper.INCOMESTATUS_NORMAL);//设置订单初始状态
        ordLogModel.setTelephone(cardPayOrderRequest.getTelephone());
        ordLogModel.setTerminalId(cardPayOrderRequest.getTerminalId());
        ordLogModel.setPaymentAmt(Double.valueOf(cardPayOrderRequest.getTradeAmount()));
        ordLogModel.setOrdId(PmpUtils.getCardOrderNum());
        return ordLogModel;
    }

    /**
     * 刷卡信息
     *
     * @param orderId
     * @return
     */
    public static CardPayOrderResponse getCardPayResponse(String orderId) {
        CardPayOrderResponse cardPayOrderResponse = new CardPayOrderResponse();
        cardPayOrderResponse.setReturnCode("0000");
        cardPayOrderResponse.setReturnMsg("刷卡信息获取成功");
        cardPayOrderResponse.setOrderId(orderId);
        return cardPayOrderResponse;
    }
}
